package com.pine.dbant.core.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.pine.dbant.core.entity.Connection;
import com.pine.dbant.core.model.vo.ConnectionVO;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Select;

import java.io.Serializable;
import java.util.List;

public interface ConnectionMapper  extends BaseMapper<Connection> {

    @Select("<script>" +
            "SELECT count(a.id) from dba_connection a,dba_relation b WHERE a.id=b.target_id and b.res_id=#{dirId} and b.type='DIR_CONNECTION'  AND a.conn_name=#{name}" +
            "<if test='connId!=null '>" +
            " and  a.id=#{connId}" +
            "</if>" +
            "</script>")
    int countByDirId(Long dirId,String name,Long connId);


    @Result(column = "properties", property = "properties", typeHandler = JacksonTypeHandler.class)
    @Select("select * from dba_connection where id=#{id}")
    @Override
    Connection selectById(Serializable id);

    @Select("select id,conn_name,ds_type,host  from dba_connection")
    List<ConnectionVO> selectVOList();
}
